package com.itheima.shop.decorator;

import com.itheima.shop.domain.Order;
import com.itheima.shop.strategy.StrategyFactory;
import com.itheima.shop.strategy.VipMoney;
import com.itheima.shop.user.SessionThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-15 12:19
 **/
@Component("vipOrderMoney")
public class VipOrderMoneySum extends DecoratorMoneySum {
    @Autowired
    private SessionThreadLocal sessionThreadLocal;
    
    @Autowired
    private StrategyFactory strategyFactory;
    
    @Override
    public void money(Order order) {
        super.money(order);
        
        //增强
        vipMoney(order);
        
    }
    
    //Vip价格运算  
    public void vipMoney(Order order) {
        //order.setPaymoney(order.getPaymoney()-5);
        //获取用户等级
        Integer level = sessionThreadLocal.get().getLevel();
        //获取价格优惠策略
        VipMoney vipMoney = strategyFactory.get(level);
        Integer payMoney = vipMoney.money(order.getPaymoney());
        order.setPaymoney(payMoney);
    }
}
